package com.example.swipytabs;
import java.util.Random; //imports  the random class

/*		public static void main(String[] args)
		{
			int length = 4; //sets the length of the array
			int[] set = new int[4]; //creates an array
			randNonENumbs test1 = new randNonENumbs("set1", length, 16); //instantiates a randNonENumbs object with a name and several values
			System.out.println(test1.toString(0, (length-1))); //prints the toString with the the perspective of the array.
			set = test1.getSet(); //sets set = to the set used in the object
		}  */

public class randNonENumbs {

		Random randgen = new Random(); //instantiates a new random object
		public String name; //creates a global string for name
		public int[] set; //creates a global array for set
		
		//the constructor for randNonENumbs, allows for length and posibility range to be entered on construction
		public randNonENumbs(String title, int numbers, int posbil) 
		{
			name = title;
			set = new int[numbers];
			for (int x = 0; x < numbers; x++) //initializes the array.
			{
				set[x] = 0;
			}
			
			setNumbers(posbil);
		}
		
		//the method that sets each part of the array to a random number
		//then compares it to the previous numbers.
		private int[] setNumbers(int blarg)
		{
			int compare = 0;
			int i;
			set[0] = randgen.nextInt(blarg); //sets the first part of the array outside of any loops
			for (i = 1; i < set.length; i++) //creates a loop for the other parts of the array depending on the length of the array
			{
					while(compare < 1)
					{
						set[i] = randgen.nextInt(blarg);
						//the loop compares the current part of the array with all the others.
						//if they are equal it will start again.
						for(int x = 0; x <= i-1; x++) 
						{			
							compare = 2;
							if(set[i] == set[x]) //if they are equal the for loop is broken
							{
								compare = 0;
								break;
							}
								
						}
						
					}
				compare = 0; //returns compare to 0 so the next iteration behaves the same way.
			}
			return set;
		}
		
		//the method returns the array's length
		public int getLength()
		{
			return set.length;
		}
		
		//creates a toString method with the set's name, and each of its values.
		public String toString(int start, int end)
		{
			String tstring = "Set Name: " + name ;
			String other = "";
			//puts the array into a series of strings
			for (int x = start; x <= end; x++)
				other += "\nset[" + x + "] = " + set[x];
			//adds the values into the string with the name.
			tstring += other;
			return tstring;
		}
		
		public int[] getSet()
		{
			return set;
		}
		

	}


